package com.bangcommunity.bbframe.fdfs.config;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;

import java.io.IOException;

public class FdfsClientConfig {
	private Configuration config;
    /**512k大小,小于这个大小的文件一次性上传,否则多次appender上传*/
    public static int BLOCK_BUFFER_SIZE_DEFAULT = 512;
    public int block_buffer_size = BLOCK_BUFFER_SIZE_DEFAULT;

	public FdfsClientConfig() throws ConfigurationException {
		super();
        config = new PropertiesConfiguration("fdfs_client.properties");

	}

	public FdfsClientConfig(String configFile) throws ConfigurationException, IOException, MyException {
		super();
        config = new PropertiesConfiguration(configFile);
        ClientGlobal.initByProperties(configFile);
        block_buffer_size = config.getInt("block_buffer_size", BLOCK_BUFFER_SIZE_DEFAULT);
	}

	public GenericKeyedObjectPoolConfig getTrackerClientPoolConfig(){
		GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
        poolConfig.setTestOnBorrow(true);
        poolConfig.setTestOnCreate(true);
        poolConfig.setTestWhileIdle(true);
		return poolConfig;
	}
	

	public GenericKeyedObjectPoolConfig getStorageClientPoolConfig(){
		GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
        poolConfig.setTestOnBorrow(true);
        poolConfig.setTestOnCreate(true);
        poolConfig.setTestWhileIdle(true);
		return poolConfig;
	}

}
